<?php
/*
 * 用户搜索类
 */
class User_Search extends Search_Base 
{
	const _CONST_TB_MAIN_    = 'user_basic';
	const _CONST_TB_MAIN_AS_ = 'u';
	const _CONST_TB_MAIN_ID_ = 'uid';
	private   static $_tb_main_keys = array(
			'uid'      => array('uid', 'common'),
			'nickname' => array('nickname', 'like'),
			'realname' => array('realname', 'like'),
			'passport' => array('passport', 'like'),
			'site'     => array('utype',    'common'),
		);

	private   static $_tb_main_gls  = array(
			'create_time',
			'logins',
			'lastlogin_time',
		);

	public function __construct ()
	{
		parent::__construct (self::_CONST_TB_MAIN_, 
				self::_CONST_TB_MAIN_AS_, self::_CONST_TB_MAIN_ID_);
	}

	protected function build_where ($query, $query_type = 'list')
	{
		$this->build_where_greater_less (self::$_tb_main_gls, $query);
		$this->build_where_keys (self::$_tb_main_keys, $query);
	}

	protected function status ($status)
	{
		return empty($status) ?  NULL 
				: Kohana::config('user.status.' . (string) $status);
	}

	protected function build_list ($result_list)
	{
        foreach ($result_list as & $u)
        {
            $uid     = Arr::get($u, 'uid');
            $role_id = user::instance($uid)->get_role_id();
            $u['role_id'] = $role_id;
        }
		return $result_list;
	}
}
